﻿@using Projectmanagement.Entity
@model Projectmanagement.Entity.Task
@{
    Layout = null;
    var level = ViewBag.level as Nullable<int>;
    List<string> listname = ViewBag.listname as List<string>;
    var files = ViewBag.files as List<TaskFile>;
    string username = Employee.CurrentUserName;
    string rolename = Employee.GetRoleName(username);

    var hist = ViewBag.hist as IQueryable<TaskTrack>;
    var owners = Model.Owners.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
    int odd = 1;
}
<div style="float: left; width: 700px; overflow: auto;">
    <table class="noline task01 task0" style="width: 100%;">
        <tr>
            <td style="width: 100px;">@Html.LabelFor(x => x.Name)
            </td>
            <td>
                <label>@Model.Name</label>
                @Html.HiddenFor(x => x.ID)<br />
            </td>
            <td style="width: 100px;">@Html.LabelFor(x => x.MilestoneID)
            </td>
            <td colspan="2">
                <label>
                    @if (@Model.Milestone != null)
                    {
                        @Model.Milestone.MilestoneName
                    }
                </label>
                <br />
            </td>
        </tr>
        <tr>
            <td style="width: 100px;">@Html.LabelFor(x => x.Owners)
            </td>
            <td colspan="4">
                <label>@Model.Owners</label>
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(x => x.TaskCode)
            </td>
            <td>
                <label>@Model.TaskCode</label>
            </td>
            <td>@Html.LabelFor(x => x.Notify)
            </td>
            <td colspan="2">
                <label>@Model.Notify</label>
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(x => x.FinishDate)
            </td>
            <td>
                <label>@Model.FinishDate</label>
            </td>
            <td>
                <label>
                    任务状态</label>
            </td>
            <td colspan="2">
                @if (Model.TaskState != null)
                {
                    <label>@Model.TaskState.Name</label>
                }
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(x => x.Content)
            </td>
            <td colspan="4">
                <label>@Model.Content</label>
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(x => x.KMLinks)
            </td>
            <td colspan="4">
                <a target="_blank" href="@Model.KMLinks">参考文档</a>
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(x => x.Deliverables)
            </td>
            <td colspan="4">
                <label>@Model.Deliverables</label>
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(x => x.StartDate)
            </td>
            <td><label style="margin: 10px;">@Model.StartDate.ToShortDateString()</label></td>
            <td>
                @Html.LabelFor(x => x.EndDate)
            </td>
            <td>
                <label style="margin: 10px;">@Model.EndDate.ToShortDateString()</label>
            </td>
            <td>
                @Html.LabelFor(x => x.Duration)<label style="margin: 10px;">@Model.Duration (天)</label>
            </td>
        </tr>
        <tr>
            <td>
                <label>
                    操作</label>
            </td>
            <td>
                @if (!string.IsNullOrEmpty(Model.Notify) && Model.Notify.Contains(Employee.CurrentUserName))
                {
                    //知会 
                }
                else
                {
                    <select name="sid" onchange=" changestate(this) ">
                        <option>-请选择-</option>
                        @if (Model.Owners.Contains(username) || rolename == "项目规划者" || Employee.LoginUserIsAdmin())
                        {
                            <option value="30">转发</option>
                            <option value="90">完成</option>
                            <option value="-10">失败</option>
                        }
                        @if (rolename == "项目规划者" || rolename == "任务分派者(PM)" || Employee.LoginUserIsAdmin())
                        {
                            <option value="-1">取消</option>
                            <option value="100">通过</option>
                            <option value="30">未完成,不通过</option>
                        }
                    </select>
                    <select name="toname" style="display: none;">
                        @foreach (var x in listname)
                        {
                            <option>@x</option>
                        }
                    </select>
                }
            </td>
            <td>
                @if (Model.Owners.Contains(Employee.CurrentUserName))
                {
                    <label>
                        文件上传</label>
                }
            </td>
            <td colspan="2">
                @if (Model.Owners.Contains(Employee.CurrentUserName))
                {
                    <a class="t-button" onclick="$('#taskfiles').click()">上传</a>
                    <input type="file" id="taskfiles" name="taskfiles" multiple="multiple" onchange="uploadfiles()"
                        style="display: none;" />
                }
            </td>
        </tr>
        <tr>
            <td>
                <label>
                    文件下载</label>
            </td>
            <td>
                <ul id="filelist">
                    @foreach (var x in files)
                    {
                        <li id="tf-@x.ID"><a href="@x.FileUrl" target="_blank">@x.FileName</a>
                            @if (Model.Owners.Contains(Employee.CurrentUserName))
                            {
                                <a href="javascript:;" onclick="deletetaskfile(@x.ID)">删除</a>
                            }
                        </li>
                    }
                </ul>
            </td>
            <td>
            </td>
            <td colspan="2">
                <div class="task01" style="text-align: right; margin-top: 20px;">
                    @if (!string.IsNullOrEmpty(Model.Notify) && Model.Notify.Contains(Employee.CurrentUserName))
                    {
                        //知会 
                    }
                    else
                    {
                        <a class="t-button" onclick=" submitchangestate() ">确定</a>
                    }
                    @if (level >= 100)
                    {
                        <a class="t-button" onclick=" $('.task01').hide();$('.task02').show(); ">编辑</a>
                    }
                </div>
            </td>
        </tr>
        <tr class="desc" style="display: none;">
            <td>
                说明
            </td>
            <td colspan="4">
                <textarea style="width: 99%; height: 100px;" name="desct"></textarea>
            </td>
        </tr>
        <tr>
            <td>
                <label>
                    操作历史</label>
            </td>
            <td colspan="4">
                <table style="width: 580px;">
                    <tbody>
                        <tr style="background-color: #f7f7f7; text-align: center; font-weight: bold;">
                            <td>
                                <label>
                                    操作人</label>
                            </td>
                            <td style="width: 100px">
                                <label>
                                    操作时间</label>
                            </td>
                            <td style="width: 100px">
                                <label>
                                    执行人</label>
                            </td>
                            <td style="width: 100px">
                                <label>
                                    状态</label>
                            </td>
                            <td style="width: 150px">
                                <label>
                                    说明</label>
                            </td>
                        </tr>
                        @foreach (var x in hist)
                        {
                            <tr @((odd++) % 2 == 0 ? "style=background-color:#f7f7f7" : "")>
                                <td>
                                    <label>@x.Creator</label>
                                </td>
                                <td>
                                    <label>@x.CreatedDate</label>
                                </td>
                                <td>
                                    <label>@x.NewOwners</label>
                                </td>
                                <td>
                                    <label>@x.NewState</label>
                                </td>
                                <td>
                                    <label>@x.Content</label>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </td>
        </tr>
    </table>
    @if (level >= 100)
    {
        using (Html.BeginForm("SaveTask", "FullCalendar", new { id = Model.ID }))
        {
        @Html.HiddenFor(m => m.TaskCode)
@*  <div class="task02"  style="padding: 0;display:none;">
          
            @Html.Partial(@"~\views\task\editortemplates\_Task.cshtml",new ProjectManagement.Models._Task())
            </div>*@
        <ul class="task02" style="padding: 0; display: none; border: 1px solid #7f9db9; border-bottom: 0;">
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.Name)</div>
                <div style="float: left; width: 260px; overflow: auto;">@Html.TextBoxFor(x => x.Name, new { style = "width:250px;" })
                    @Html.HiddenFor(x => x.ID)<br />
                    @Html.ValidationMessageFor(x => x.Name)
                </div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.Milestone.MilestoneName)</div>
                <div style="float: left; width: 260px; overflow: auto;">@Html.DropDownListFor(x => x.MilestoneID, new SelectList(Projectmanagement.Utl.CH.DB.Milestone.Where(s => s.Projectid == Model.ProjectID), "ID", "MilestoneName"), new { style = "width:250px;" })<br />
                    @Html.ValidationMessageFor(x => x.Name)
                </div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.Owners)</div>
                <div style="float: left; width: 260px; overflow: auto;">@Html.HiddenFor(x => x.Owners)<span
                    class="oname">@Model.Owners</span>
                    @Html.Partial("_PartialMemberSelect", "#ProjectID")<br />
                    @Html.ValidationMessageFor(x => x.Owners)
                    @Html.HiddenFor(x => x.ProjectID)
                </div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.Notify)</div>
                <div style="float: left; width: 595px; overflow: auto;">@Html.TextBoxFor(x => x.Notify, new { style = "width:590px; height:22px;" })
                    @Html.ValidationMessageFor(x => x.Notify)
                </div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.FinishDate)</div>
                <div style="float: left; width: 260px; overflow: auto;">@Html.EditorFor(x => x.FinishDate, new { style = "width:250px;" })</div>
                <div style="float: left; width: 60px; overflow: auto;">
                    <label>
                        任务状态</label></div>
                <div style="float: left; width: 250px; overflow: auto;">
                    @if (Model.TaskState != null)
                    {
                        <label>@Model.TaskState.Name</label>
                    }</div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.Content)</div>
                <div style="float: left; width: 595px; overflow: auto;">@Html.TextAreaFor(x => x.Content, new { rows = "4", cols = "81" })<br />
                    @Html.ValidationMessageFor(x => x.Content)</div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.KMLinks)</div>
                <div style="float: left; width: 595px; overflow: auto;">
                    @Html.TextAreaFor(x => x.KMLinks, new { rows = "4", cols = "81" })<br />
                    @Html.ValidationMessageFor(x => x.KMLinks)</div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.Deliverables)</div>
                <div style="float: left; width: 595px; overflow: auto;">@Html.TextAreaFor(x => x.Deliverables, new { rows = "4", cols = "81" })<br />
                    @Html.ValidationMessageFor(x => x.Deliverables)</div>
            </li>
            <li class="clearfix">
                <div style="float: left; width: 100px; overflow: auto;">@Html.LabelFor(x => x.StartDate)</div>
                <div style="float: left; width: 260px; overflow: auto;">@Html.EditorFor(x => x.StartDate, new { style = "width:250px;" })<br />
                    @Html.ValidationMessageFor(x => x.StartDate)</div>
                <div style="float: left; width: 60px; overflow: auto;">@Html.LabelFor(x => x.EndDate)</div>
                <div style="float: left; width: 250px; overflow: auto;">@Html.EditorFor(x => x.EndDate, new { style = "width:250px;" })<br />
                    @Html.ValidationMessageFor(x => x.EndDate)</div>
            </li>
        </ul>            
        

        <div class="task02" style="text-align: right; margin-top: 20px; display: none;">
            @if (!string.IsNullOrEmpty(Model.Notify) && Model.Notify.Contains(Employee.CurrentUserName))
            {
                //知会 
            }
            else
            {
                <a class="t-button" onclick=" SaveTask(); ">确定</a> 
                <a class="t-button" onclick=" $('.task02').hide();$('.task01').show(); ">返回</a>
            }
        </div>
        }
    }
</div>
<div style="width: 310px; float: right; overflow: auto;">
    <div>
        <label>
            任务留言</label>
    </div>
    <textarea id="Contents" name="Contents" rows="4" style="width: 95%;"></textarea>
    <a class="t-button" onclick=" savemsg() ">留言</a>
    <div id="commentList" class="dierye_3" style="font-size: 0.8em;">
    </div>
</div>
<style>
    .noline
    {
        width: 100%;
    }
    .noline, .noline tr, .noline td
    {
        border: 1px solid #7f9db9;
    }
    #filelist, #filelist a
    {
        font-size: 12px;
    }
    /**********Clear Fix */
    .clearfix:after
    {
        content: ".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;
    }
    .clearfix
    {
        display: inline-block;
    }
    /* Hide from IE Mac \*/
    .clearfix
    {
        display: block;
    }
    /* End hide from IE Mac */
    /* end of clearfix */
    .task02 li
    {
        margin-bottom: 5px;
        border-bottom: 1px solid #7f9db9;
        padding-bottom: 5px;
    }
    .t-datepicker{margin-top:4px;}
</style>
<script src="../../Scripts/ajaxfileupload.js"></script>
<script>
    function uploadfiles() {
        $.ajaxFileUpload({
            url: "/task/UploadTaskFiles/@Model.ID",
            secureuri: false,
            fileElementId: 'taskfiles',
            dataType: "json",
            success: function (data, status) {
                if (data.validate) {
                    $("#filelist").append(decodeURIComponent(data.msg));
                }
            }
        });
    }

    function deletetaskfile(id) {
        var name = $("#tf-" + id).find("a").eq(0).text();
        if (confirm("确定将" + name + "删除吗")) {
            $.ajax({
                url: "/task/deletefile/" + id,
                type: "post",
                dataType: "json",
                success: function (data, status) {
                    if (data == "OK") {
                        $("#tf-" + id).remove();
                    }
                }
            });
        }
    }

    function savemsg() {
        $("#Contents").val($.trim($("#Contents").val()));
        if ($("#Contents").val() == "") {
            alert("请输入留言");
            return;
        }

        $.post('/Task/savemsg', { taskid: $("input[name=ID]").val(), msg: $("#Contents").val() }, function (result) {
            $("#Contents").val("");

            $.post('/Task/GetCommentList', { taskid: $("input[name=ID]").val() }, function (result) {
                $('#commentList').html(result);
                $(".all").removeClass("allR");
            });
        });


    }

    $(function () {
        $.post('/Task/GetCommentList', { taskid: $("input[name=ID]").val() }, function (result) {
            $('#commentList').html(result);

            $(".all").removeClass("allR");
        });

        $("input[name=returnurl]").val(window.location);
    });

    function changestate(e) {
        if ($(e).children("option:selected").text() == "转发") {
            $("select[name=toname]").show();
        } else {
            $("select[name=toname]").hide();
        }
        if ($(e).children("option:selected").text() == "-请选择-") {
            $(".desc").hide();
        } else {
            $(".desc").show();
        }
    }

    function SaveTask() {
        $.ajax({
            url: "/Task/_SaveTask/" + $("input[name=ID]").val(),
            type: "post",
            data: {
                id: $("textarea[name=ID]").val(),
                Name: $("#Name").val(),
                Owners: $("#Owners").val(),
                Notify: $("#Notify").val(),
                FinishDate: $("textarea[name=FinishDate]").val(),
                Content: $("textarea[name=Content]").val(),
                KMLinks: $("textarea[name=KMLinks]").val(),
                Deliverables: $("textarea[name=Deliverables]").val(),
                StartDate: $("input[name=StartDate]").val(),
                EndDate: $("input[name=EndDate]").val(),
                FinishDate: $("input[name=FinishDate]").val(),
                MilestoneID: $("select[name='MilestoneID']").val()
            },
            dataType: "Json",
            success: function (data, status) {
                if (status == "success") {
                    var windowintask = $('#TastMessageT').data('tWindow');
                    var windowinproject = $('#TastMessage').data('tWindow');
                    if (windowintask != null) {
                        windowintask.close();
                    }
                    if (windowinproject != null) {
                        windowinproject.close();
                    }
                    $(".t-grid .t-refresh").trigger('click');
                }
            }
        });
    }
    function submitchangestate() {

        $("textarea[name=desct]").val($.trim($("textarea[name=desct]").val()));
        if ($("textarea[name=desct]").val() == "") {
            alert("说明不能为空");
            return;
        }
        if ($("select[name=sid] option:selected").text() == "-请选择-") {
            alert("请选择一个状态");
            return;
        }
        if ($("select[name=sid] option:selected").text() == "转发" &&
            $("select[name=toname] option:selected").text() == "-请选择-") {
            alert("请选择一个用户");
            return;
        }

        $.ajax({
            url: "/task/savestatechange/" + $("input[name=ID]").val(),
            type: "post",
            data: {
                des: $("textarea[name=desct]").val(), state: $("select[name=sid] option:selected").val(),
                uname: $("select[name=toname] option:selected").text()
            },
            dataType: "Json",
            success: function (data, status) {
                var window = $('#TastMessage').data('tWindow');
                if (window) {
                    //location.href = "/task";
                    window.close();
                }
                else {
                    location.href = "/task";
                }


            }
        });
    }
</script>
